<template>
  <view :style="colorStyle">
    <view
      class="spikeModule"
      :style="{
        paddingTop: `${info.style.pTop * 2}rpx`,
        paddingLeft: `${info.style.pLeft * 2}rpx`,
        paddingRight: `${info.style.pRight * 2}rpx`,
        paddingBottom: `${info.style.pBottom * 2}rpx`,
        marginTop: `${info.style.mTop * 2}rpx`,
        marginLeft: `${info.style.mLeft * 2}rpx`,
        marginRight: `${info.style.mRight * 2}rpx`,
        marginBottom: `${info.style.mBottom * 2}rpx`,
        borderRadius: `${info.radius * 2}rpx`,
        background: `${info.bgColor}`,
      }"
    >
      <view
        class="info2"
        :style="{
          background: `${
            info.colortem == 1
              ? 'linear-gradient(180deg, var(--view-op-ten024) 0%, var(--view-op-ten0) 100%)'
              : 'linear-gradient(180deg, ' +
                info.titleBgColor1 +
                ' 0%, ' +
                info.titleBgColor2 +
                ' 100%)'
          }`,
        }"
      ></view>
      <div class="info1">
        <div class="titlebox flex aitems between">
          <div
            class="title flex aitems"
            :style="{ color: `${info.titleColor}` }"
          >
            <div>
              {{
                info.value.length == 0
                  ? "N元N件活动"
                  : info.value[0].title || ""
              }}
            </div>
            <div class="timebox flex aitems" v-if="info.iskill">
              <u-count-down
                :time="downTime"
                format="HH:mm:ss"
                autoStart
                millisecond
                @change="downonChange"
                @finish="downfinish"
              >
                <view class="flex aitems">
                  <view
                    class="time"
                    :style="{
                      background: `${
                        info.colortem == 1 ? 'var(--view-theme)' : info.color
                      }`,
                    }"
                  >
                    <text class="">{{
                      timeData.hours > 10
                        ? timeData.hours
                        : "0" + timeData.hours
                    }}</text>
                  </view>
                  <text
                    class="time1"
                    :style="{
                      color: `${
                        info.colortem == 1 ? 'var(--view-theme)' : info.color
                      }`,
                    }"
                    >:</text
                  >
                  <view
                    class="time"
                    :style="{
                      background: `${
                        info.colortem == 1 ? 'var(--view-theme)' : info.color
                      }`,
                    }"
                  >
                    <text class="">{{
                      timeData.minutes > 10
                        ? timeData.minutes
                        : "0" + timeData.minutes
                    }}</text>
                  </view>
                  <text
                    class="time1"
                    :style="{
                      color: `${
                        info.colortem == 1 ? 'var(--view-theme)' : info.color
                      }`,
                    }"
                    >:</text
                  >
                  <view
                    class="time"
                    :style="{
                      background: `${
                        info.colortem == 1 ? 'var(--view-theme)' : info.color
                      }`,
                    }"
                  >
                    <text class="">{{
                      timeData.seconds > 10
                        ? timeData.seconds
                        : "0" + timeData.seconds
                    }}</text>
                  </view>
                </view>
              </u-count-down>
              <!-- <div class="time" :style="{ background: `${info.color}` }">
                08
              </div>
              <div class="time1" :style="{ color: `${info.color}` }">:</div>
              <div class="time" :style="{ background: `${info.color}` }">
                08
              </div>
              <div class="time1" :style="{ color: `${info.color}` }">:</div>
              <div class="time" :style="{ background: `${info.color}` }">
                08
              </div> -->
            </div>
          </div>
          <div
            class="more flex aitems"
            :style="{ color: `${info.titleColor}` }"
            v-if="info.moreShow == 1"
            @click="gourl(`/pages/activities/nynj?id=${info.value[0].id}`)"
          >
            <span>{{ info.more }}</span>
            <u-icon
              name="arrow-right"
              :color="`${info.titleColor}`"
              size="12"
            ></u-icon>
          </div>
        </div>

        <div class="sellerbox">
          <div
            class="sellerList"
            v-for="(q, index, key) in list"
            :key="key"
            @click="gourl(`/pages/goods/detail?id=${q.goodsId}`)"
          >
            <div class="sellerinfo1 flex">
              <image
                class="sellerLogo"
                :src="q.goodsImg"
                alt=""
                mode="aspectFill"
              />
              <div class="sellerNameBox flex between">
                <div class="sellerNameBox1">
                  <div class="sellerName ellipsis2">
                    {{ q.goodsName }}
                  </div>
                  <div class="labelbox flex aitems">
                    <div
                      class="label"
                      v-if="q.goodsTagName"
                      v-for="b in q.goodsTagName.split(',')"
                      :style="{
                        color: `${
                          info.colortem == 1 ? 'var(--view-theme)' : info.color
                        }`,
                        border: `0.5px solid ${
                          info.colortem == 1 ? 'var(--view-theme)' : info.color
                        }`,
                      }"
                    >
                      {{ b }}
                    </div>
                  </div>
                  <div class="sale">销量:{{ q.salesVolume }}</div>
                </div>
                <div class="price flex aitems between">
                  <div
                    class="pricebox flex aitems"
                    :style="{
                      color: `${
                        info.colortem == 1 ? 'var(--view-theme)' : info.color
                      }`,
                    }"
                  >
                    <div class="unit">￥</div>
                    <div class="num">{{ q.goodsPrice }}</div>
                  </div>
                  <div
                    class="btn"
                    :style="{
                      background: `linear-gradient(270deg,${
                        info.colortem == 1
                          ? 'var(--view-op-ten6)'
                          : hexToRgb(info.color, 0.6)
                      } 0.96%,${
                        info.colortem == 1 ? 'var(--view-theme)' : info.color
                      } 97.01%)`,
                    }"
                  >
                    立即购买
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </view>
  </view>
</template>

<script>
import { HTTP_STATUS } from "../../../servers/config";
import colors from "@/mixins/color";
import { publicityInfo, publicityGoodsPage } from "@/servers/servers.js";
import { go } from "../../../utils/wxAPI";
export default {
  mixins: [colors],
  props: {
    info: {
      default: {},
    },
  },
  data() {
    return { detail: {}, list: [], timeData: {}, downTime: 99999999 };
  },
  async mounted() {
    if (this.info.value.length !== 0) {
      await this.publicityInfo();
    }
  },
  methods: {
    async publicityInfo() {
      let { data } = await publicityInfo({
        id: this.info.value[0].id,
      });
      if (data.code == HTTP_STATUS.RUSELT_SUCCESS) {
        let info = data.data;
        let now = Date.now();
        info.config = info.config ? JSON.parse(info.config) : {};
        let endTime = new Date(info.endTime.replace(/-/g, "/")).getTime();
        let beginTime = new Date(info.beginTime.replace(/-/g, "/")).getTime();

        if (now < beginTime) {
          info.statusText = "距开始";
          this.downTime = beginTime - now;
        } else if (endTime - now > 0) {
          info.statusText = "距结束";
          this.downTime = endTime - now;
        } else {
          info.statusText = "已结束";
          this.downTime = 0;
        }
        if (info.statusText !== "已结束") {
          this.publicityGoodsPage();
        }
        this.detail = info;
      }
    },

    async publicityGoodsPage() {
      let { data } = await publicityGoodsPage({
        current: 1,
        size: 2,
        publicityId: this.info.value[0].id,
      });
      if (data.code == HTTP_STATUS.RUSELT_SUCCESS) {
        let list = data.data.records;
        this.list = list;
      }
    },

    downonChange(e) {
      let hours = e.hours + e.days * 24;
      e.hours = hours;
      this.timeData = e;
    },

    downfinish() {
      this.publicityInfo();
    },

    hexToRgb(hex, o) {
      console.log(hex);
      // 移除十六进制颜色中的'#'
      let sanitizedHex = hex.replace("#", "");

      // 解析红、绿、蓝色值
      let r = parseInt(sanitizedHex.substring(0, 2), 16);
      let g = parseInt(sanitizedHex.substring(2, 4), 16);
      let b = parseInt(sanitizedHex.substring(4, 6), 16);

      return `rgb(${r}, ${g}, ${b},${o})`;
    },
    gourl(url) {
      go(url);
    },
  },
};
</script>

<style lang="scss" scoped>
.spikeModule {
  position: relative;
  overflow: hidden;

  .info1 {
    position: relative;
    z-index: 1;
    .titlebox {
      .title {
        font-weight: bold;
        font-size: 36rpx;
        .timebox {
          margin-left: 16rpx;
          .time {
            border-radius: 8rpx;
            font-size: 24rpx;
            color: #fff;
            background: #f65b49;
            width: 50rpx;
            height: 50rpx;
            line-height: 50rpx;
            text-align: center;
          }
          .time1 {
            color: #f65b49;
            font-size: 24rpx;
            font-weight: bold;
            margin: 0 8rpx;
          }
        }
      }
      .more {
        color: #1f1f1f;
        font-size: 24rpx;
      }
    }

    .sellerbox {
      .sellerList {
        position: relative;
        // background: #c2c2c2;
        // box-shadow: 0px 1px 4px #c2c2c2;
        margin: 32rpx 0 0;
        // border-radius: 14px;
        // padding: 12px;
        overflow: hidden;
        // .yinying {
        //   position: absolute;
        //   bottom: 0;
        //   width: 100%;
        //   height: 40px;
        //   left: 0;
        //   background: linear-gradient(rgba(255, 255, 255, 0.5), #fff);
        //   z-index: 1;
        // }
        .filter {
          background-position: 50%;
          background-repeat: no-repeat;
          background-size: cover;
          filter: blur(0px);
          width: 100%;
          height: 100%;
          box-sizing: border-box;
          position: absolute;
          left: 0;
          top: 0;
          overflow: hidden;
          // background: #666;
          .gaosi-content {
            // background: #000;
            // position: absolute;
            // left: 0;
            // top: 0;
            // width: 100%;
            // height: 100%;
            // opacity: 0.6;
          }
        }
        .sellerinfo1 {
          position: relative;
          z-index: 1;
          .sellerLogo {
            width: 230rpx;
            height: 230rpx;
            border-radius: 24rpx;
            object-fit: cover;
          }
          .sellerNameBox {
            width: calc(100% - 16rpx - 230rpx);
            margin-left: 16rpx;
            flex-direction: column;
            height: 260rpx;
            .sellerName {
              color: #1f1f1f;
              font-size: 28rpx;
            }
            .labelbox {
              flex-wrap: wrap;
              margin: 16rpx 0;
              .label {
                color: #5ccedd;
                font-size: 22rpx;
                border-radius: 8rpx;
                border: 1rpx solid #5ccedd;
                margin: 0 8rpx 8rpx 0;
                padding: 4rpx 16rpx;
              }
            }
            .sale {
              color: #858585;
              font-size: 22rpx;
            }
            .price {
              .pricebox {
                color: #f65b49;
                margin: 24rpx 0 0;
                font-weight: bold;
                .unit {
                  font-size: 28rpx;
                  position: relative;
                  top: 2rpx;
                }
                .num {
                  font-size: 40rpx;
                }
              }
            }
            .btn {
              border-radius: 60rpx;
              background: #5ccedd;
              color: #fff;
              font-size: 24rpx;
              padding: 16rpx 34rpx;
            }
          }
        }
      }
    }
  }
  .info2 {
    height: 172rpx;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
  }
}
</style>
